
Page({
  data: {
    userInfo: {}
  },
  authLogin(){
    const that = this
    wx.login({
      success: (res)=>{
        that.getUserInfo(res.code)
      },
    })
  },
  getUserInfo(code){
    let data = this.data.userInfo
    wx.request({
      url: `http://localhost:8080/wechat/login?code=${code}`,
      method:"POST",
      header:{
        'content-type':'application/json'
      },
      success(res){
        data = res.data.data
        if(data){
          wx.setStorageSync('userInfo',data)
          wx.showToast({
            title: '登录成功',
            duration:800
          })
          setTimeout(()=>{
            wx.navigateBack()
          },1000)
        }else{
          wx.showToast({
            title:'登陆失败',
            icon:'none'
          })
        }
      }
    })
  }
});